class lustre::client (
  $lustreclient_version = "2.0-17.public",
  $lustreclient_group   = "public",
  $lustreui_verson      = "2.0-17.UI",
  $local_initd          = false,
  $clientversion        = "2.5.3-2.6.32_754.17.1.el6.x86_64.x86_64",
  $lustre6client        = "6client",
  $ibenable             = false,
) {

  
  # $lustre_release=regsubst($kernel_version,'-','_')
  # config remount.pl on lustre client
  #rclocal::script { "remount":
  #  priority => "10",
  #  content  => "/root/bin/remount.pl",
  #}
  #file{ "/root/bin/remount.pl":
  #    mode       =>  '755',
  #    owner      =>  'root',
  #    group      =>  'root',
  #    source     =>  "puppet:///modules/lustre/remount.pl"
  #}
  define lustrepkgforce ( $pkg_name = $title,    $source,  ) {
      exec { "force_${pkg_name}":
         command => "/bin/rpm -e lustre-config; sleep 10; /bin/rpm -ivh --force  ${source} --nodeps",
         path => "/bin/rpm",
         unless => "/bin/rpm -q  ${pkg_name} ",
      }
  }
  define rmlustrepkg {
      exec { "remove_${name}" :
         command => "/bin/rpm -e ${name} --nodeps",
         path => "/bin/rpm",
         onlyif => "/bin/rpm -q  ${name} ",
      }
  }
  define rmlustrem {
      exec { "remove_${name}" :
         command => "/bin/rpm -e ${name} --nodeps --noscripts",
         path => "/bin/rpm",
         onlyif => "/bin/rpm -q  ${name} ",
      }
  }


  if $local_initd {
    file{ "/etc/init.d/lustre":
        mode       =>  '755',
        owner      =>  'root',
        group      =>  'root',
        source     =>  "puppet:///modules/lustre/lustre"
    }
  }



  # add for befs2 config



# install lustre pkg
  case $facts['os']['release']['major'] {
   '5': {
         $lustre_release=regsubst($kernel_version,'-','_')
	 package { 'lustre':
	      provider => 'rpm',
	      ensure => 'installed',
	      source => "http://202.122.33.67/quattor/lustre/lustre-${lustre_version}${lustre_release}.x86_64.rpm",
	      require => Package['lustre-modules'],
	 }

	 package { 'lustre-modules':
	      provider => 'rpm',
	      ensure => 'installed',
	      source => "http://202.122.33.67/quattor/lustre/lustre-modules-${lustre_version}${lustre_release}.x86_64.rpm",
	 }
	 package { 'lustre-tests':
	      provider => 'rpm',
	      ensure => 'installed',
	      source => "http://202.122.33.67/quattor/lustre/lustre-tests-${lustre_version}${lustre_release}.x86_64.rpm",
	      require => Package['lustre'],
	 } 
    }

    '6': {
           yumrepo {"lustre":
             baseurl   =>  "http://mirror.ihep.ac.cn/yum/lustre/${$lustre6client}/",
             descr => "lustre client",
             enabled => 1,
             gpgcheck => 0,
             priority => 40,
             before   => Yumrepo['site']
           }->
           package { [
	              "lustre-client-$clientversion",
		      "lustre-client-debuginfo-$clientversion",
		      "lustre-iokit-$clientversion",
		      "lustre-client-tests-$clientversion",
		      "lustre-client-modules-$clientversion",
		      ]:
             ensure            => installed,
             require           => Yumrepo['site']
           }
           #package {"sg3_utils":
           #  ensure   => 'installed',
           #  require  => Yumrepo['site']
           #}
     }
     '7': {
       if $ibenable {
         $lustrerepo = "${facts['os']['release']['full']}_ib"
	     }
       else {
         $lustrerepo = "${facts['os']['release']['full']}"
       }
        yumrepo {"lustre":
          baseurl   =>  "http://${mirrorserver}/yum/lustre/${lustrerepo}/client/",
          descr => "lustre client",
          enabled => 1,
          gpgcheck => 0,
          priority => 20,
          before   => Yumrepo['site']
        }
        yumrepo {"e2fs":
          baseurl   =>  "http://${mirrorserver}/yum/lustre/public/e2fsprogs/1.44.3.wc1/el7/",
          descr => "e2fs",
          enabled => 1,
          gpgcheck => 0,
          priority => 20,
          before   => Yumrepo['site']
        }
        package { ["lustre-iokit",
                   "lustre-client",
                   "lustre-client-dkms",
                   "lustre-client-debuginfo",
                   "kmod-lustre-client"]:
                 ensure => 'installed',
                 require => Yumrepo['site'],
       }
       package { [ "lustre-client-tests",
                   "kmod-lustre-client-tests"]:
                 ensure => 'absent',
                 require => Yumrepo['site'],
       }

    }
     /8|9/: {
       if $ibenable {
         $lustrerepo = "${facts['os']['release']['full']}_ib"
   }   
       else {
         $lustrerepo = "${facts['os']['release']['full']}"
       }
        yumrepo {"lustre":
          baseurl   =>  "http://${mirrorserver}/yum/lustre/${lustrerepo}/client/",
          descr => "lustre client",
          enabled => 1,
          gpgcheck => 0,
          priority => 20,
          before   => Yumrepo['site']
        }
        yumrepo {"e2fs":
          baseurl   =>  "http://${mirrorserver}/yum/lustre/public/e2fsprogs/1.47.0.wc6/el${facts['os']['release']['major']}/",
          descr => "e2fs",
          enabled => 1,
          gpgcheck => 0,
          priority => 20,
          before   => Yumrepo['site']
        }
        package { ["lustre-iokit",
                   "lustre-client",
                   "lustre-client-dkms",
                   "lustre-client-debuginfo",
                   "kmod-lustre-client"]:
                 ensure => 'installed',
                 require => Yumrepo['site'],
       }
       package { [ "lustre-client-tests",
                   "kmod-lustre-client-tests"]:
                 ensure => 'absent',
                 require => Yumrepo['site'],
       }

    }

  } ->
      if $login_node {
           case $facts['os']['release']['major'] {
           '5': {
              lustre::lustreconfigforce { 'lustre-config':
                name     => "lustre-config",
                version  => "$lustreui_verson.sl5",
                source   => "http://202.122.33.67/yum/lustre/lustre-config-${lustreui_verson}.sl5.x86_64.rpm",
                require  => Package['lustre'],
             }
           }
          '6': {
              lustre::lustreconfigforce { 'lustre-config':
                name     => "lustre-config",
                version  => $lustreui_verson,
                source   => "http://202.122.33.67/yum/lustre/lustre-config-${lustreui_verson}.x86_64.rpm",
             }
           }
           /7|8|9/: {
              lustre::lustreconfigforce { 'lustre-config':
                name     => "lustre-config",
                version  =>  $lustreui_verson,
                source   => "http://202.122.33.67/yum/lustre/lustre-config-${lustreui_verson}.x86_64.rpm",
                require  => Package["lustre-client"],
               }
             }
         }
       }
       else {
           case $facts['os']['release']['major'] {
           '5': {
              lustre::lustreconfigforce { 'lustre-config':
                name     => "lustre-config",
                version  =>  $lustreclient_version,
                source   => "http://202.122.33.67/yum/lustre/lustre-config-${lustreclient_version}.x86_64.rpm",
                require  => Package['lustre'],
                }
             }
           '6': {
              lustre::lustreconfigforce { 'lustre-config':
                name     => "lustre-config",
                version  =>  $lustreclient_version,
                source   => "http://202.122.33.67/yum/lustre/lustre-config-${lustreclient_version}.x86_64.rpm",
               }
             }
           /7|8|9/: {
              lustre::lustreconfigforce { 'lustre-config':
                name     => "lustre-config",
                version  =>  $lustreclient_version,
                source   => "http://202.122.33.67/yum/lustre/lustre-config-${lustreclient_version}.x86_64.rpm",
                require  => Package["lustre-client"],
               }
             }
           }
    }
}
